package base.form {
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import base.tf.TextFieldUtils;
	import base.dspObj.DoOperations;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	
	public class MessageFormForTf extends Sprite {
		
		private var tfLabel: TextField;
		private var arrStrBadMessage: Array;
		private var timerCloseMessage: Timer;
		
		public function MessageFormForTf(arrStrBadMessage: Array, tFormatMessage: TextFormat): void {
			this.createLabel(tFormatMessage);
			this.arrStrBadMessage = arrStrBadMessage;
			this.alpha = 0;
		}
		
		protected function createLabel(tFormatMessage: TextFormat): void {
			this.tfLabel = TextFieldUtils.createTextField(tFormatMessage);
			this.tfLabel.text = " ";
			this.addChild(this.tfLabel);
		}
		
		public function showAndCloseMessage(typeMessage: uint): void {
			if (typeMessage < this.arrStrBadMessage.length) {
				this.tfLabel.text = this.arrStrBadMessage[typeMessage];
				DoOperations.hideShow(this, 1);
				if (this.timerCloseMessage != null) this.timerCloseMessage.stop();
				this.timerCloseMessage = new Timer(Math.round(Math.pow(this.tfLabel.text.length, 0.62) * 150), 1);
				this.timerCloseMessage.addEventListener(TimerEvent.TIMER_COMPLETE, this.onTimerCompleteCloseMessage);
				this.timerCloseMessage.start();
			}
		}
		
		public function closeMessage(): void {
			if ((this.timerCloseMessage) && (this.timerCloseMessage.running)) {
				this.timerCloseMessage.dispatchEvent(new TimerEvent(TimerEvent.TIMER_COMPLETE));
				this.timerCloseMessage.stop();
			}
		}
		
		protected function onTimerCompleteCloseMessage(e: TimerEvent): void {
			DoOperations.hideShow(this, 0);
		}
		
	}

}